package com.dzt.androidframework.activity;

import android.os.Bundle;


import com.dzt.androidframework.fragment.FragmentAbout;
import com.dzt.androidframework.fragment.FragmentBase;
import com.dzt.androidframework.fragment.FragmentSettingMain;
import com.dzt.androidframework.fragment.FragmentUpdate;
import com.dzt.androidframework.fragment.FragmentUpdatePwd;
import com.dzt.androidframework.fragment.FragmentsManager;
import com.dzt.androidframework.R;

import java.util.ArrayList;
import java.util.List;

public class ActivitySetting extends ActivityTitle {
	public static final int INDEX_SETTING_MAIN = 0x00; //设置主界面
	public static final int INDEX_SETTING_PWD = 0x01;//修改wifi密码
	public static final int INDEX_SETTING_UPDATE = 0x02;//版本更新
	public static final int INDEX_SETTING_ABOUT = 0x03;//关于界面
	private int currentIndex;

	private FragmentsManager manager;

	@Override
	protected int getLayoutId() {
		return R.layout.activity_setting;
	}

	@Override
	protected void initParams() {
		List<FragmentBase> fragments = new ArrayList<>();
		fragments.add(new FragmentSettingMain());
		fragments.add(new FragmentUpdatePwd());
		fragments.add(new FragmentUpdate());
		fragments.add(new FragmentAbout());
		currentIndex = INDEX_SETTING_MAIN;
		manager = new FragmentsManager(getSupportFragmentManager(),
				fragments, R.id.fragments_container, currentIndex);
		setTitleView(R.string.title_setting);
	}

	@Override
	protected void initData(Bundle savedInstanceState) {

	}

	@Override
	protected String[] initPermissions() {
		return null;
	}

	public void showFragmentByIndex(int index) {
		if (manager != null) {
			currentIndex = index;
			manager.showFragmentByIndex(index);
			if(currentIndex == INDEX_SETTING_MAIN){
				setTitleView(R.string.title_setting);
			}else if(currentIndex == INDEX_SETTING_PWD){
				setTitleView(R.string.text_update_pwd);
			}else if(currentIndex == INDEX_SETTING_UPDATE){
				setTitleView(R.string.text_update);
			}else if(currentIndex == INDEX_SETTING_ABOUT){
				setTitleView(R.string.text_about);
			}
		}
	}

	@Override
	public void onBackPressed() {
		if (currentIndex != INDEX_SETTING_MAIN) {
			showFragmentByIndex(INDEX_SETTING_MAIN);
		} else {
			super.onBackPressed();
		}
	}
}
